<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改地址簿')"/>
    <link th:href="@{/css/city-picker/city-picker.css}" rel="stylesheet"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-custAddr-edit" th:object="${custAddr}">
        <input name="id" th:field="*{id}" type="hidden" id="id">
        <div class="form-group">
            <label class="col-sm-3 control-label">地址代码：</label>
            <div class="col-sm-8">
                <input name="addrId" th:field="*{addrId}" class="form-control" type="text" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">客户名称：</label>
            <div class="col-sm-8">
                <input name="customerId" id="customerId" th:field="*{customerId}" class="form-control hidden"
                       type="text" readonly required>
                <input name="customerId" id="customerName" th:field="*{customerName}" class="form-control" type="text"
                       readonly onclick="checkCustomer()" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">姓名：</label>
            <div class="col-sm-8">
                <input name="userName" th:field="*{userName}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">联系方式：</label>
            <div class="col-sm-8">
                <input name="userTele" id="userTele" th:field="*{userTele}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">省市区：</label>
            <div class="col-sm-8">
                <input name="userArea" th:field="*{userArea}" class="form-control" type="text"
                       data-toggle="city-picker">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">详细地址：</label>
            <div class="col-sm-8">
                <input name="userAddress" th:field="*{userAddress}" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script th:src="@{/js/cityPicker/city-picker.data.js}"></script>
<script th:src="@{/js/cityPicker/city-picker.js}"></script>
<script type="text/javascript">
    var prefix = ctx + "bus/custAddr";
    $("#form-custAddr-edit").validate({
        focusCleanup: true,
        rules: {
            userTele: {
                isPhone: true,
            }
        }
    });


    function submitHandler() {
        var id = $("#id").val();
        var url = "";
        if (id == "") {
            url = prefix + "/add";
        } else {
            url = prefix + "/edit";
        }
        if ($.validate.form()) {
            $.operate.save(url, $('#form-custAddr-edit').serialize());
        }
    }

    //选择客户代码页面
    function checkCustomer() {
        $.modal.open("选择客户信息", "/pageUtil/chooseCust");
    }

    //选中客户代码
    function checkedCustomer(customer) {
        $('#customerId').val(customer.customerId);
        $('#customerName').val(customer.customerName);
    }
</script>
</body>
</html>